package com.lagou.homework.model3;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author Hanpeng
 * @date 2021/12/23 20:04
 * @description:
 */
public class NumSortReducer extends Reducer<IntWritable, NullWritable,IntWritable,IntWritable> {
    private int counter;
    IntWritable keyOut = new IntWritable();
    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for(NullWritable value:values) {
            counter++;
            keyOut.set(counter);
            context.write(keyOut, key);
        }
    }
}
